package com.zzh;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();
        list.add("张三");
        list.add("张三");
        list.add("张三");
        list.add("张三");
        System.out.println(list);


        ArrayList<String> newList = new  ArrayList<String> ((new HashSet<String>(list)));

        System.out.println(newList);

        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("张三");
        hashSet.add("李四");
        hashSet.add("王五");
        hashSet.add("赵六");

        System.out.println(hashSet);


         Iterator<String> iterator = hashSet.iterator();
         while  (iterator.hasNext()) {
             String next = iterator.next();
             System.out.println(next);
         }

         for(String name:hashSet){
             System.out.println("name="+name);
         }

         hashSet.forEach(new Consumer<String>() {
             @Override
             public void accept(String s) {
                 System.out.println(s);
             }
         });

         hashSet.forEach(s-> System.out.println(s));
         hashSet.forEach(System.out::println);

         Student student = new Student("张三",20);
        System.out.println(student.toString());
    }


}
